package com.feriki.msync.meta;

import io.milvus.param.collection.FieldType;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author luozhida
 * @create 2024-07-09
 */
@Data
public class MilvusCollectionMeta {

    private String collectionName;
    private String collectionDescription;
    private int shardsNum;
    private List<FieldTypeMeta> fieldTypes = new ArrayList<>();
    private boolean enableDynamicField;

    public void getFieldTypesFrom(List<FieldType> milvusFieldTypes,String vectorFieldName) {
        if (milvusFieldTypes != null) {
            milvusFieldTypes.forEach(fieldType -> {
                FieldTypeMeta fieldTypeMeta = new FieldTypeMeta();
                fieldTypeMeta.transferFrom(fieldType);
                if(fieldType.getName().equals(vectorFieldName)){
                    fieldTypeMeta.setVectorKey(true);
                }
                this.fieldTypes.add(fieldTypeMeta);
            });
        }
    }

    public List<FieldType> toMilvusFieldTypes() {
        if (fieldTypes != null) {
            return fieldTypes.stream().map(FieldTypeMeta::toMilvusFieldType).collect(Collectors.toList());
        }
        return null;
    }

}
